package game.view.char{
	
	import game.common.components.base.DisplayElement;
	import game.controller.animation.AnimationCtr;
	import game.data.constant.name.BehaviorName;
	import game.data.constant.name.CoreName;
	import game.data.constant.name.NotificationName;
	import game.data.constant.name.RoleName;
	import game.data.constant.state.Direction;
	import game.data.constant.system.Path;
	import game.data.structure.role.RoleData;
	import game.model.animation.AnimationModel;
	
	import lib.gameEngine.common.data.Notification;
	import lib.gameEngine.core.View;
	import lib.utile.loader.BulkLoader;
	import lib.utile.memory.Memory;
	
	public class CharacterView	 extends View{
		
		private var _loader:BulkLoader;
		private var _displayArr:Array;
		private var _class:Class;   //TODO  测试用变量，可以删除，目前用来缓存
		
		public function CharacterView(){
			super(CoreName.CHARACTER);
			_loader = BulkLoader.getLoader(CoreName.LOAD);
			_displayArr = new Array();
		}
		
		override protected function registerNotify():void{  //注册通知
			this.addNotify(NotificationName.TEST,onTest);
			this.addNotify(NotificationName.ENTER_FRAME,onEnterFrame);
		}
		
		private function onEnterFrame(note:Notification):void{
			for(var i:uint = 0; i < _displayArr.length;i++){
				var dis:DisplayElement = _displayArr[i];
				dis.play();
			}
		}
		
		private function createDisplay():void{
			var display:DisplayElement = new DisplayElement();
/*			var roleData:RoleData = new RoleData();
			roleData.name = RoleName.ROLE;*/
			var animationModel:AnimationModel = getModel(CoreName.ANIMATION) as AnimationModel;
			display.model = animationModel;
			display.behavior = BehaviorName.WAIT;
			display.direction = Direction.FRONT;
			display.play();
			sprite = getSprite();   //TODO  需要重新对舞台进行分层
			_displayArr.push(display);
			sprite.addChild(display);
			if(!getController(CoreName.ANIMATION))registerController(new AnimationCtr());
		}
		
		
		private function onTest(note:Notification):void{
			//createDisplay();
			for(var i:uint = 0; i<1; i ++){
				createDisplay();
			}

			var fps:Memory = new Memory();
			fps.x = 800;
			sprite.addChild(fps);
			
			this.sendNotify(new Notification(NotificationName.PLAY));
		}
	}
}